﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace AzureBlob
{
    class BlobInfo
    {
        CloudBlockBlob blob;
        public BlobInfo(CloudBlockBlob blob)
        {
            this.blob = blob;
        }

        public CloudBlockBlob Blob
        {
            get
            {
                return blob;
            }
        }

        public string Name
        {
            get
            {
                return blob.Uri.Segments[blob.Uri.Segments.Count() - 1];
            }
        }

        public string ContentType
        {
            get
            {
                return blob.Properties.ContentType;
            }
        }

        public long Length
        {
            get
            {
                return blob.Properties.Length;
            }
        }

        public DateTime LastModified
        {
            get
            {
                return blob.Properties.LastModifiedUtc;
            }
        }

        public string CacheControl
        {
            get
            {
                return blob.Properties.CacheControl;
            }
        }

        public object Icon
        {
            get
            {
                int p = blob.Uri.PathAndQuery.LastIndexOf('.');
                if (p != -1)
                    return SysTool.GetSystemIconByExt(blob.Uri.PathAndQuery.Substring(p));
                else
                    return SysTool.GetSystemIconByExt("");
            }
        }

        public Uri Uri
        {
            get
            {
                return blob.Uri;
            }
        }
        
        public override string ToString()
        {
            return Name;
        }
    }
}
